package com.happystreet.info
{
	import com.happystreet.GlobalGameConstants;
	import com.happystreet.config.GameConfig;
	import com.happystreet.utils.CustomUtils;

	/**
	 *材料信息 
	 * @author Liseen
	 * 
	 */	
	public class ItemInfo
	{
		//销售价格
		public var salesPriceInCoins:int;
		//类型
		public var type:uint;
		//元件名
		public var symbolName:String;
		//名称
		public var name:String;
		//商店类型
		public var shopType:uint;
		//是否打折
		private var isSale:Boolean = false;
		//组索引
		public var groupIndex:int;
		
		public var priceInCoins:uint;
		public var isNew:Boolean = false;
		public var isInUpdatePopUp:Boolean = false;
		public var priceInCash:uint;
		public var id:uint;
		public var typeName:String;
		public var isInStore:Boolean = false;
		public var salesPriceInCash:int;
		public var isCash:Boolean = false;
		public function ItemInfo(data:XML)
		{
			this.typeName = data.parent().@name;
			this.type = data.parent().@type;
			this.groupIndex = getItemGroupIndexFromType(this.type);
			this.id = data.@id;
			this.shopType = data.@shopType;
			this.symbolName = data.@symbol;
			this.name = data.@name;
			this.priceInCoins = data.@priceCoins;
			this.priceInCash = data.@priceCash;
			this.salesPriceInCoins = data.@saleCoins;
			this.salesPriceInCash = data.@saleCash;
			this.isCash = CustomUtils.booleanFromXmlString(data.@isCash, false);
			this.isNew = CustomUtils.booleanFromXmlString(data.@isNew, false);
			this.isSale = CustomUtils.booleanFromXmlString(data.@isSale, false);
			this.isInStore = CustomUtils.booleanFromXmlString(data.@isInStore, true);
			this.isInUpdatePopUp = CustomUtils.booleanFromXmlString(data.@isInUpdatePopUp, false);
		}
		/**
		 *依据类型获取item组的索引 
		 * @param type
		 * @return 
		 * 
		 */		
		private static function getItemGroupIndexFromType(type:int):int
		{
			var index:int;
			switch (type)
			{
				case GlobalGameConstants.BACKGROUND_TYPE:
				case GlobalGameConstants.PAVEMENT_TYPE:
				case GlobalGameConstants.WALL_SHAPE_TYPE:
				case GlobalGameConstants.WALL_MATERIAL_TYPE:
				case GlobalGameConstants.ROOF_TYPE:
					index = 0;
					break;
				case GlobalGameConstants.DOOR_TYPE:
				case GlobalGameConstants.STORE_WINDOW_TYPE:
				case GlobalGameConstants.WINDOW_TYPE:
					index = 1;
					break;
				case GlobalGameConstants.BANNER_TYPE:
				case GlobalGameConstants.WALL_DECORATION_TYPE:
				case GlobalGameConstants.OUTSIDE_DECORATION_TYPE:
					index = 2;
					break;
			}
			return index;
		}
		
		/**
		 *获取销售价格 *0.34打折么？
		 * @return 
		 * 
		 */		
		public function getSellingPrice():int
		{
			var price:int = (this.isOnSale() ? this.salesPriceInCoins : this.priceInCoins);
			return Math.floor(price * 0.34);
		}
		/**
		 *是否在销售 
		 * @return 
		 * 
		 */		
		public function isOnSale():Boolean
		{
			return ((this.isSale) && (GameConfig.areThereSales() > 0));
		}
	}
}